#
#  Copyright 2010 Andrew Kroh
#
#  Kroh-IO is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  Kroh-IO is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import os


# Import the environment which is setup for JNI:
Import('env', 'JAVA_CLASSES_DIR', 'JAVA_DEPS_DIR')
Import('JAVA_SRC_DIR', 'DIST_DIR', 'AUTO_INCLUDE_DIR')
Import('JAR_NAME')


# Clone the environment so changes 
# cannot affect global build env:
java_env = env.Clone()


# Compile Java source code:
compile_class_path = os.path.join(Dir(JAVA_DEPS_DIR).path, 'slf4j-api-1.5.11.jar')
java_target = java_env.Java(
    target = JAVA_CLASSES_DIR,  
    source = JAVA_SRC_DIR,
    JAVACLASSPATH = compile_class_path,
    JAVACFLAGS = '-target 1.5 -g')
Clean(java_target, JAVA_CLASSES_DIR)


# Create a Jar from the compiled sources:
jar_target = java_env.Jar(
    target = os.path.join(Dir(DIST_DIR).path, JAR_NAME),
    source = java_target)

# Build JNI Header Files:
jni_target = java_env.JavaH(
    target = File(os.path.join(Dir(AUTO_INCLUDE_DIR).path, 'kroh_serial_port.h')),
    source = os.path.join(Dir(JAVA_CLASSES_DIR).path, 'kroh/io/KrohSerialPort.class'),
    JAVACLASSDIR = JAVA_CLASSES_DIR)
Clean(jni_target, AUTO_INCLUDE_DIR)
